package com.shenmazong.servereduresume.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shenmazong.servereduresume.dto.TbInformation;
import com.shenmazong.servereduresume.dto.TbLevel;
import com.shenmazong.servereduresume.dto.TbProject;
import com.shenmazong.servereduresume.dto.TbSkill;
import com.shenmazong.servereduresume.mapper.TbSkillMapper;
import com.shenmazong.servereduresume.service.TbSkillService;
import com.shenmazong.utils.ResultResponse;
import com.shenmazong.vo.BatchChooseIdVo;
import com.shenmazong.vo.ListParamVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 *
 */
@Service
public class TbSkillServiceImpl extends ServiceImpl<TbSkillMapper, TbSkill>
implements TbSkillService {

    @Autowired
    private TbSkillMapper tbSkillMapper;

    @Override
    public ResultResponse findAllSkill(ListParamVo listParamVo) {
        Page<TbSkill> page = new Page<>(listParamVo.getCurrent(), listParamVo.getSize());

        Page<TbSkill> tbSkillPage = tbSkillMapper.selectPage(page, null);
        return ResultResponse.SUCCESS(tbSkillPage);
    }

    @Override
    public ResultResponse saveSkill(TbSkill tbSkill) {
        try {
            tbSkillMapper.insert(tbSkill);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultResponse.FAILED();
        }
        return ResultResponse.SUCCESS();
    }

    @Override
    public ResultResponse updateSkill(TbSkill tbSkill) {
        try {
            tbSkillMapper.updateById(tbSkill);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultResponse.FAILED();
        }
        return ResultResponse.SUCCESS();
    }

    @Override
    public ResultResponse deleteSkill(BatchChooseIdVo batchChooseIdVo) {
        if (batchChooseIdVo.getIds().size() <= 0){
            return ResultResponse.FAILED("至少选择一个删除");
        }
        try {
            for (Long id : batchChooseIdVo.getIds()) {
                UpdateWrapper<TbSkill> updateWrapper = new UpdateWrapper<TbSkill>().eq("schoolyard_id", id);
                updateWrapper.set("delete_flag",1);
                tbSkillMapper.delete(updateWrapper);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return ResultResponse.FAILED();
        }
        return ResultResponse.SUCCESS();
    }
}




